#include "defines.h"

int test(double * B, int N, int T, int Bx, int tb) {

	double (* A)[N + 2 * XSTART] = (double(*)[N + 2 * XSTART]) B;

	int bx = Bx - 2 * tb * XSLOPE;
	int ix = Bx + bx;
	int nb0[2] = { myfloor(N-Bx,ix), myfloor(N-Bx,ix) + 1 };	
	int nrestpoints = N % ix;
	int bx_first_B1 = (Bx + nrestpoints)/2;
	int bx_last_B1  = (Bx + nrestpoints) - bx_first_B1;
	int xright[2] = {bx_first_B1 + Bx + XSTART,  bx_first_B1 + (Bx - bx)/2 + XSTART};
	int level = 0;
	int x, xx, t, tt;
	register int xmin, xmax;

	for (tt = -tb; tt < T ;  tt += tb ){
	#pragma omp parallel for private(xmin,xmax,t,x) 
		for(xx = 0; xx <nb0[level]; xx++) {
			for(t= max(tt, 0) ; t <min( tt + 2*tb,  T); t++){
				xmin = (level == 1 && xx == 0) ?             XSTART : (xright[level] - Bx + xx*ix + myabs((tt+tb),(t+1))*XSLOPE);
				xmax = (level == 1 && xx == nb0[1] -1) ? N + XSTART : (xright[level]      + xx*ix - myabs((tt+tb),(t+1))*XSLOPE);
				#pragma ivdep
				#pragma vector always
				for(x = xmin; x < xmax; x++){
					kernel(A);
				}
			}
		}
		level = 1 - level;
	}
}
